# -*- coding: utf-8 -*-
""" Include some functions and declarations needed throughout controllers"""
from tgext.admin import AdminController
from tg import expose, flash, require, url, request, redirect,config
from pylons.i18n import ugettext as _, lazy_ugettext as l_
from pylons.controllers.util import etag_cache
#from catwalk.tg2 import Catwalk
from repoze.what import predicates
from lifepyscle.lib.base import BaseController
from lifepyscle.model import DBSession, metadata
from lifepyscle.controllers.error import ErrorController
from lifepyscle import model
import re

global risks,frequencies,time_units
risks = {   0:'No Risk',\
            1:'Very Low Risk',\
            2:'Low Risk',\
            3:'Medium Risk',\
            4:'High Risk',\
            5:'Very High Risk',\
        }

frequencies = ['days','weeks','months','years']


def isValidEmail(address):
    print address
    is_ok = re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$",address)
    print is_ok
    if not is_ok:
        return False
    else:
        return True

def risk2txt(risk):
    if not isinstance(risk,int):
        raise TypeError, "risk must be an integer, not %s"%type(risk)
    else:
        if risk < 1 or risk > 5:
            raise ValueError, "risk must be between 0 and 5. You declared %d"%risk
        else:
            return risks[risk]

# delete these if they are no longer needed. Remove references in other controllers first
MAX_RECUR = config.get('max_event_recurrences')
choice_recur_count = range(1,MAX_RECUR+1)    
choice_reminder_days = range(1,32)
